package com.biomatch.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;

import java.util.Locale;

@Component
public class Internationalize {

    @Value("${server.language}")
    private String language;

    @Autowired
    private MessageSource messageSource;

    public String getMessage(String msg) {
        return messageSource.getMessage(msg, null, getLocale());
    }

    public Locale getLocale(){
        Locale locale = Locale.SIMPLIFIED_CHINESE;
        switch (language) {
            case "Simplified Chinese": {
                locale = Locale.SIMPLIFIED_CHINESE;
                break;
            }
            case "Traditional Chinese": {
                locale = Locale.TRADITIONAL_CHINESE;
                break;
            }
            case "English": {
                locale = Locale.ENGLISH;
                break;
            }
        }
        return locale;
    }
}
